package fr.mmt.gisfizz.service;

import fr.mmt.gisfizz.entity.User;
import fr.mmt.gisfizz.repository.UserRepository;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.transaction.annotation.Transactional;

/**
 * User Details Service. <br/>
 *
 * @author Mathieu MAST
 */
@Transactional
@Slf4j
public class CustomUserDetailsService implements UserDetailsService {

    @Resource
    private UserRepository userRepository;

    @Override
    public User loadUserByUsername(String login) throws UsernameNotFoundException {
        log.debug("Load user '{}' for identification", login);
        return userRepository.findByLogin(login);
    }
}
